<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
java.lang.String urlpath = request.getContextPath();
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>代理信息编辑查看</title>
<meta http-equiv="expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<link rel="stylesheet" href="../css/admin_style.css" />
<script type="text/javascript" src="../js/jquery-1.8.2.js"></script>
<script language="javascript" src="../js/validate.js"></script>
</head>
<body>
<div class="wrap">
<div class="nav3 mb10">
	<ul class="cc">
		<li><a href="${baseIndentType.url2  }">${baseIndentType.name  }</a></li>
		<li class="current"><a href="toTaobaoGuanzhuAdd?base=${baseIndentType.id }">${baseIndentType.name  }订单</a></li>
          
        <span class="admin_tips" style="margin-left:10px;line-height:22px;font-weight:bold;">您目前余额：<b style="cursor: pointer; height: 25px; line-height: 25px; font-weight: 700; display: inline-block; color: green;" id="fans_a" onclick="openNewUrl('menu_44','充值消费记录','/agent/accountRecordUI!query.action');return false;" title="查看充值消费记录">${curUser.money }</b></span>    </ul>
</div>
<div class="admin_info mb10" style="display: block;">
    <h3 class="h1">提示信息</h3>
    <div class="legend">
    ${baseIndentType.pointOut}
    </div>
 </div>
<form action="addTaobaoGuanzhuIndent" method="post"  onsubmit="return submitForm(this);">

<input name="base" id="base" type="hidden" value="${baseIndentTypeList[0].id }"/>
<input id = "startNumber" name="userIndent.startNumber" type="hidden" value="" />
<input id="targetTitle" name="userIndent.targetTitle" type="hidden" value="" />
<input name="price" id="price" type="hidden" value="${priceList[0] }" />
<input name="userIndent.brandId" id="brandId" type="hidden" value="" />
<h2 class="h1"><b>订单详情</b></h2>
<div class="admin_table mb10">
      <table width="100%" cellspacing="0" cellpadding="0">
				<tbody><tr class="tr1 vt">
          <td class="td1">当前产品</td>
          <td class="td2" style="font-weight:bold">
			${baseIndentType.name}--<span id="cTypeName">${baseIndentTypeList[0].name}</span> 价格为<span id="pro_price" style="color:red">${priceList[0] }</span><span id="typeUnit">${baseIndentTypeList[0].unit }</span>
		  </td>
        </tr>
		<tr class="tr1 vt">
          <td class="td1">店铺首页网址<span class="s1">*</span></td>
          <td class="td2"><input  style="float: left;margin-top:7px;" type="text" name="userIndent.targetUrl" id="bill.targetUrl" class="input input_wb" onblur="checkUrl(this.value);" validate="目标网址或者ID||notnull">
          <div id="wbinfo"></div>
          <div class="tip_a" id="showResult_target" style="clear:both;"> </div>
		 </td>
        </tr>
        <tr class="tr1 vt">
          <td class="td1">类型<span class="s1">*</span></td>
          <td class="td2">
          
          	<c:forEach var="indentType" items="${indentTypeList }" varStatus="i" step="1">
          		<c:if test="${i.index==0 }">
          			<c:if test="${indentType.userBaseIndentType.enable==1 }">
          			<input class="type_radio" name="typeRadio"
          				   indent_base="${indentType.userBaseIndentType.id }"
          			       indent_name="${indentType.userBaseIndentType.name }" 
          				   indent_price = "${indentType.price }" 
          				   indent_minAmount = "${indentType.userBaseIndentType.minAmount }"
          				   indent_maxAmount = "${indentType.userBaseIndentType.maxAmount }"
          				   indent_unitPrice = "${indentType.userBaseIndentType.unit2 }"
          				   indent_unitName = "${indentType.userBaseIndentType.unit }"
          				 type="radio"  checked="checked" 
          				/>
          				${indentType.userBaseIndentType.name }
          				</c:if>
          		</c:if>
          		<c:if test="${i.index!=0 }">
          		<c:if test="${indentType.userBaseIndentType.enable==1 }">
          			<input class="type_radio" name="typeRadio"
          				   indent_base="${indentType.userBaseIndentType.id }"
          				   indent_name="${indentType.userBaseIndentType.name }" 
          				   indent_price = "${indentType.price }" 
          				   indent_minAmount = "${indentType.userBaseIndentType.minAmount }"
          				   indent_maxAmount = "${indentType.userBaseIndentType.maxAmount }"
          				   indent_unitPrice = "${indentType.userBaseIndentType.unit2 }"
          				   indent_unitName = "${indentType.userBaseIndentType.unit }"
          			  type="radio"
          			  />
          				${indentType.userBaseIndentType.name }
          				</c:if>
          		</c:if>	
          		
          		
          	</c:forEach>
          
		  </td>
        </tr>
        <tr class="tr1 vt">
          <td class="td1">本次数量<span class="s1">*</span></td>
          <td class="td2"><span id="wbfans" style="float:left;color:green;font-weight:bold"></span><input name="userIndent.number" value="" id="bill.billAmount" onblur="validatePrice()" validate="本次加粉数量||notnull" type="text" class="input input_wc" alt="数量:空"><div class="tip_a" id="showResult_allnum"></div></td>
        </tr>

		<tr class="tr1 vt" id="feeall">
          <td class="td1">本次费用总计</td>
          <td class="td2">
			<span id="fee_all" style="font-weight:bold;color:red;font-size:18px">0</span>元。
			<input type="hidden" id="totle_price" name="userIndent.totalPrice" value=""/>
		  </td>
        </tr>
		<tr class="tr1 vt">
          <td class="td1">备注</td>
          <td class="td2"><textarea name="userIndent.remark" id="bill.remark" class="textarea"></textarea><div class="tip_a" id="showResult_remark">备注信息，防止混淆忘记</div></td>
        </tr>
      </tbody></table>
</div>
<div class="tac mb10">
	<span class="btn"><span><button type="submit" id="sbutton">提 交</button></span></span><span class="admin_tips" id="submitcheck">请先填写正确的微博地址或微博ID，验证通过后方可提交。</span>
</div>
</form>
<div class="c"></div>
</div>
<script type="text/javascript">
$(".type_radio").bind("change",function(){
	changeType(this);
});

 function changeType(radio){
	  product={
			    price:$(radio).attr("indent_price"),
			    minAmount:$(radio).attr("indent_minAmount"),
			    maxAmount:$(radio).attr("indent_maxAmount"),
			    unitPrice:$(radio).attr("indent_unitPrice")
			 };
	  $("#cTypeName").text($(radio).attr("indent_name"));
	  $("#pro_price").text($(radio).attr("indent_price"));
	  $("#typeUnit").text($(radio).attr("indent_unitName"));
	  $("#base").val($(radio).attr("indent_base"));
	  $("#price").val($(radio).attr("indent_price"));
	  
	  if(product.minAmount==product.maxAmount){
		  $("#bill\\.billAmount").attr("value",product.maxAmount);
		  $("#bill\\.billAmount").attr("disabled","disabled");
		  validatePrice();
	  }else{
		  $("#bill\\.billAmount").removeAttr("value");
		  $("#bill\\.billAmount").removeAttr("disabled");
	  }
	  
 }
 function checkUrl(target){
        $("#sbutton").attr("disabled",true);
        $("#submitcheck").show();
        $("#wbinfo").html("");
        if(!target)
        {
            $("#showResult_target").html("<span style='color:red'>目标网址或者ID不能为空！</span>");
            return false;
        }
        if(target.length<=3){
            $("#showResult_target").html("<span style='color:red'>目标网址或者ID输入不正确！</span>");
            return false;
        }
        $("#showResult_target").html("正在验证...请稍后");
        $.ajax({
            type:"POST",
            url:"<%=urlpath%>/ajax/getIndentTargetInfo_taobao_tm_gz",
            dataType:"json",
            data:'base=${base}&targetUrl='+escape(target),
            success:function(msg)
            {
                 callBack(msg);
            }
        });
}
    function callBack(msg){
       if(msg['name']){
          //$("#wbfans").html(msg['followers_count']+'&nbsp;+&nbsp;');
          var utype = msg['type'];
          
          $("#wbinfo").html("<div style='border:1px dashed lightgreen;padding:6px;width:230px;height:60px;margin-top:6px;'><div style='float:left;line-height:18px;padding-left:2px;'>"+msg['name']+"<br>当前<span style='color:green;text-decoration:underline;'>"+msg['number']+"</span>关注</div></div>");
          $("#startNumber").attr("value",msg['number']);
          $("#targetTitle").attr("value",msg['name']);
          if(msg['brandId']){
        	  $("#brandId").attr("value",msg['brandId']); 
          }else{
        	  $("#brandId").attr("value",""); 
          }
          
          $("#showResult_target").html("");
          $("#sbutton").attr("disabled",false);
           $("#submitcheck").hide();
        }else {
             $("#showResult_target").html("<span style='color:red'>目标网址或者ID不正确，获取数据失败！</span>");
        }
    }

    var user={
    	    balance:"${curUser.money }"
    	}
    	 var product={
    	    price:${priceList[0]},
    	    minAmount:${baseIndentTypeList[0].minAmount},
    	    maxAmount:${baseIndentTypeList[0].maxAmount},
    	    unitPrice:${baseIndentTypeList[0].unit2}
    	 };
    	 
    	initPrice();
    	 
    	 function initPrice(){
    		 
    		 if(product.minAmount==product.maxAmount){
    			 billAmount = product.minAmount;
    			 $("#bill\\.billAmount").val(billAmount);
    			 $("#bill\\.billAmount").attr("disabled","disabled");
    			 validatePrice();
    		 }
    	 }
 function validatePrice()
 {
     var billAmount = parseInt($("#bill\\.billAmount").val());
     if(billAmount>0)
     {
         if(billAmount < product.minAmount)
         {
             billAmount = product.minAmount;
         }
         else if(billAmount > product.maxAmount)
         {
             billAmount = product.maxAmount;
         }
         
         $("#bill\\.billAmount").val(billAmount);
         var fee_base = Math.round(billAmount * product.price)/product.unitPrice;
         var fee_all = fee_base;
         $("#fee_base").html(fee_base);
         if(fee_all>user.balance)
         {
             alert("余额不足，当前订单："+fee_all+"元，您目前余额"+user.balance+"元，请充值后继续！");
             return false;
         }
         fee_all = Math.round(fee_all*100)/100;
         $("#fee_all").html(fee_all);
         $("#totle_price").attr('value',fee_all);
         return true;
     }
     return false;
 }


function showConfirm(info,href){
 info = info ;//+ "<br>操作理由：<input type='text' id='____operationReason'><br>操作密匙：<input type='text' id='____operationPassword'>";
 showDialog({type:"confirm",message:info,onOk:function(){
   //var ____operationReason=document.getElementById("____operationReason").value;
   //if(!____operationReason || ____operationReason==""){alert("请输入操作理由");return false;}
   location.href=href;
   //openNewUrl('user'+new Date().getTime(),info,href);
   return true;
 }});
}
var operations=document.getElementsByTagName("a");
for(var i=0;i<operations.length;i++){
    var obj=operations[i];
    var confirm=obj.getAttribute("confirm");
    if(!confirm || confirm!="yes")continue;
    obj.attachEvent("onclick",function(e){
        e=window.event||e;
        var el=e.srcElement;
        //test();
        if(el.href.indexOf("javascript:void")==-1)
        el.href="javascript:void(0);showConfirm('"+"确认执行"+el.innerText+"操作？！"+"','"+el.href+"');"
        return false;
    })
}

var allInputs = document.getElementsByTagName('input');
if(allInputs && allInputs.length>0){
	for(var i=0; i<allInputs.length;i++)
	{
		var ipt = allInputs[i].parentNode;
		if(ipt.tagName=='LI'&& allInputs[i].type=='radio')
		{
			allInputs[i].checked && (ipt.className='current');
			ipt.onclick = function(){radioWithWords(this)};
		}
	}
}
</script>
<script type="text/javascript">
    if (typeof (HTMLElement) != "undefined" && !window.opera) {
    HTMLElement.prototype.__defineGetter__("outerHTML", function () {
        var a = this.attributes, str = "<" + this.tagName, i = 0; for (; i < a.length; i++)
            if (a[i].specified)
                str += " " + a[i].name + '="' + a[i].value + '"';
        if (!this.canHaveChildren)
            return str + " />";
        return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    HTMLElement.prototype.__defineSetter__("outerHTML", function (s) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df = r.createContextualFragment(s);
        this.parentNode.replaceChild(df, this);
        return s;
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
    });
}
if (typeof (HTMLElement) != "undefined" && !window.opera) {
    HTMLElement.prototype.__defineGetter__("outerHTML", function () {
        var a = this.attributes, str = "<" + this.tagName, i = 0; for (; i < a.length; i++)
            if (a[i].specified)
                str += " " + a[i].name + '="' + a[i].value + '"';
        if (!this.canHaveChildren)
            return str + " />";
        return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    HTMLElement.prototype.__defineSetter__("outerHTML", function (s) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df = r.createContextualFragment(s);
        this.parentNode.replaceChild(df, this);
        return s;
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
    });
}
</script>
<script type="text/javascript">
    var valueControls={//能直接用 obj.value赋值的控件名及Type
        "input":"text,password,hidden",
        "select":"select-one",
        "textarea":"textarea"
    };
    
    var formData={};
    for(var id in formData){//铺数据
      var obj=document.getElementById(id);
      if(id && obj){//checkBox
        var tagName=obj.tagName.toLowerCase();
        if(obj.type){
          var type=obj.type.toLowerCase();
          if(valueControls[tagName] && valueControls[tagName].indexOf(type)!=-1){
            if(eval("document.getElementById(\""+id+"\")")){
              document.getElementById(id).value=formData[id];
            }
          }else{
             if(type=="radio" || type=="checkbox"){
              initRadioOrCheckBox(id); 
             }
             if(type=="select-multiple"){
              initMultiSelect(id);
             }
          }
        }else{
           obj.innerHTML=formData[id]; 
        }
      }
    }
    function initRadioOrCheckBox(id){
      var servingTimes=document.getElementsByName(id);
      for(var s=0;s<servingTimes.length;s++){
         if(servingTimes[s].type=="checkbox")
           servingTimes[s].checked=false;
      }
      if(formData[id]){
        var servingTimesValue=formData[id].split(",");
        for(var s=0;s<servingTimesValue.length;s++){
         for(var i=0;i<servingTimes.length;i++){
            if(servingTimes[i].value==servingTimesValue[s].trim())
            servingTimes[i].checked=true;
         }
       }
      }else{
       for(var i=0;i<servingTimes.length;i++){
         if(servingTimes[i].type=="checkbox")
           servingTimes[i].checked=true;
       }
      }
   }
   function initMultiSelect(id){
      var selOptions=document.getElementById(id).options;
      for( var i=0;i<selOptions.length;i++){
         selOptions.selected=false;
      }
      if(formData[id]){
        var selOptionsValue=formData[id].split(",");
        for(var s=0;s<selOptionsValue.length;s++){

         for(var i=0;i<selOptions.length;i++){
            if(selOptions[i].value==selOptionsValue[s].trim())
            selOptions[i].selected=true;
         }
       }
      }else{
       for(var i=0;i<selOptions.length;i++){
         selOptions[i].selected=false;
       }
      }
   }
</script>    
<script type="text/javascript">
function getQueryString(form,param) {
        var datastring = '';
        var inputs = form.getElementsByTagName('INPUT');
        for (var i = 0; i < inputs.length; i++) {
            if(inputs[i].name==param)continue;
            
            switch (inputs[i].getAttribute('type')) {
                case 'text':
                    datastring = plamostr(inputs[i], datastring);
                    break;
                case 'hidden':
                    datastring = plamostr(inputs[i], datastring);
                    break;
                case 'checkbox':
                    if (inputs[i].checked) {
                        datastring = plamostr(inputs[i], datastring);
                    }
                    break;
                case 'radio':
                    if (inputs[i].checked) {

                        datastring = plamostr(inputs[i], datastring);
                    }
                    break;
            }
        }
        var textareas = form.getElementsByTagName('TEXTAREA');
        for (var i = 0; i < textareas.length; i++) {
            datastring = plamostr(textareas[i], datastring);
        }
        var selectes = form.getElementsByTagName('SELECT');
        for (var i = 0; i < selectes.length; i++) {
            datastring = plamostr(selectes[i], datastring);
        }
        if(param){
            document.getElementById(param).value=datastring;
        }
        return datastring;
    }
    function plamostr(object, datastring) {
        /**
         *拼装Form数据字符串
         */
        if (datastring.length > 0) {
            datastring += '&' + object.getAttribute('name') + '=' + object.value;
        } else {
            datastring += object.getAttribute('name') + '=' + object.value;
        }
        return datastring;
    }
</script><script type="text/javascript">
    function submitForm(form){
      if(!frmSubmit(form))return false;
      if(!validatePrice())return false;
      document.getElementById("sbutton").disabled=true; 
      return true;
    }
</script>
</body></html>

